package com.ceba.test.modules.admin.entity;


import com.ceba.base.web.entity.IBase;
import com.ceba.cebacer.KeyLoaderType;
import com.ceba.cebautils.StringUtil;
import com.ceba.cebacer.CertificateLevelEnum;
import com.ceba.test.base.helper.SystemHelper;

import java.util.Date;
import java.util.Map;


public class ISign extends IBase {

	private static final long serialVersionUID = 1L;
	private String id="";
	private String stampName="";
	private String stampFlag="";
	private String stampID="";
	private String stampPath="images/null.png";
	private String imgWidth="0";
	private String imgHeight="0";
	private String stampX="0";
	private String stampY="0";
	private String lockFlag="0";
	private String matchName="";
	private String stampPage="1";
	private String qianWaterMarkFlag="";
	private String inertText="";
	private String qfStampFlag="false";
	private String createTime="";
	private String stampNameHtml="";
	
	private String qfRuleHtml;//骑缝章规则
    private String qfRuleId="";//骑缝章规则id
    private String otherStampId;//其他印章Id
    private String signStampId;//签名印章Id
    private String waterStampId;//水印Id
    private String mergeId;//合并首尾页Id
    
    //资质章
    private String credentialsFlag="false";
    private String credentialsHtml;
    private String credentialsId;
    
	
	//服务器IP
	private String serverIp;
	//服务器端口
	private int serverPort;
	//服务器地址后缀
	private String serverUrlSuffix="";
	// 多服务器IP+PORT
	private String multiServer;
	//签名类型  1--key  2--服务器类型
	private int keyType = 1;
	
	//加密方式 1-RSA 2-SM2
	private int encodeSignType;
	
	// 0-关键字签名 1-位置定位  2-骑缝章，默认0
	private int signType = 0;
	//证书编号
	private String cerNo;
	//秘钥名称
	private String keyName;

	//密钥名称
	private String privateKeyName;

	//是否更改pdf属性
	private String encropytToPdf;

	//是否打印印章0-打印 1-不打印 ，默认0
	private int printSeal = 0;
	//签名域名称
	private String signFieldName="signature";
	// 签名原因
	private String signReason;
	//签名地址
	private String signLocation;
	//0--修订 3-验证
	private int certificationLevel = CertificateLevelEnum.YZ3.getType();
	//是否需要补全证书  0-补全  1-不补
	private int needCompleteCer = 0;
	//补全哪家公司证书
	private int fatherType = 1;
	
	
	//关键字签章失败后，是否用位置定位签章 0 -是  1-否
	private int keyNeedRect = 0;
	//是否多关键字签章 0为多关键字签章，1为单关键字签章
	private int multiKeyWord = 1;
	
	//印章位置1- 重叠 2-居下 3 - 居右
	private int moveType = 1;
	//0正序 1倒序
	private int positive = 0;
	
	//位置定位签名页
	private int rectPageNo = 1;
	// 签章在PDF中左边距
	private float rectLeft = 0;
	
	private float rectRight  = 0;
	
	private float rectTop  = 0;
	
	private float rectBottom = 0;
	
	
	//是否多页签名0为所有页骑缝章图片签名，1为仅首页骑缝章图
	private int qfMultiSign = 1;
	//骑缝章所在高度，把页高度分为10000等分，默认为4000
	private int qfPosCoord;
	//骑缝章首页印章宽度，1-100 为百分比
	private int qfStartWidth = 20;
	
	//辅助字段，不存在数据库
	private boolean pdfHasSM2Signed = false;
	
	//辅助字段，不存在数据库
	private boolean pdfHasRSASigned = false;
	
	//保证数字签名和直接插入签名位置一致，添加的微调参数
	public static int _param = 4;

	//允许打印 0-允许  1-不允许 ALLOW_PDF_PRINT
	private int  allowPdfPrint = 0;

	//允许PDF内容复制 0-允许 1-不允许 ALLOW_PDF_CONTENT_COPY
	private int allowPdfContentCopy = 1;

	/**
	 * 骑缝章的起止页
	 * null：默认值。为文档首页和末页
	 * 数字：指定数字的起止页
	 * 非数字：根据关键字找到骑缝章起止页
	 */
	private String startPageOfQifeng;
	private String endPageOfQifeng;

	public String getStartPageOfQifeng() {
		return startPageOfQifeng;
	}

	public void setStartPageOfQifeng(String startPageOfQifeng) {
		this.startPageOfQifeng = startPageOfQifeng;
	}

	public String getEndPageOfQifeng() {
		return endPageOfQifeng;
	}

	public void setEndPageOfQifeng(String endPageOfQifeng) {
		this.endPageOfQifeng = endPageOfQifeng;
	}

	private Map<String, String> customDateToContent;

	public Map<String, String> getCustomDateToContent() {
		return customDateToContent;
	}

	public void setCustomDateToContent(Map<String, String> customDateToContent) {
		this.customDateToContent = customDateToContent;
	}

	/**
	 * 在本节接口规则中，是否需要数字签名；
	 * isNeedSinature=true，需要数字签名，按照接口规则中的“数字签名(加密)签/章配置”来数字签名
	 * isNeedSinature=false，不需要数字签名，忽略接口规则中的“数字签名(加密)签/章配置”

	 */
	private boolean isNeedSinature = true;

	private boolean shouldOfd = false;

	/**
	 * 印章有效起始日期。用于ofd签章
	 */
	private String validStartOfSeal;

	/**
	 * 印章有效终止日期。用于ofd签章
	 */
	private String validEndOfSeal;

	public boolean isNeedSinature() {
		return isNeedSinature;
	}

	public void setNeedSinature(boolean needSinature) {
		isNeedSinature = needSinature;
	}

	public boolean isShouldOfd() {
		return shouldOfd;
	}

	public void setShouldOfd(boolean shouldOfd) {
		this.shouldOfd = shouldOfd;
	}

	public String getValidStartOfSeal() {
		return validStartOfSeal;
	}

	public void setValidStartOfSeal(String validStartOfSeal) {
		this.validStartOfSeal = validStartOfSeal;
	}

	public String getValidEndOfSeal() {
		return validEndOfSeal;
	}

	public void setValidEndOfSeal(String validEndOfSeal) {
		this.validEndOfSeal = validEndOfSeal;
	}

	public int getAllowPdfPrint() {
		return allowPdfPrint;
	}

	public void setAllowPdfPrint(int allowPdfPrint) {
		this.allowPdfPrint = allowPdfPrint;
	}

	public int getAllowPdfContentCopy() {
		return allowPdfContentCopy;
	}

	public void setAllowPdfContentCopy(int allowPdfContentCopy) {
		this.allowPdfContentCopy = allowPdfContentCopy;
	}

	public ISign() {
	}
	public String getStampPath() {
		return stampPath;
	}
	public void setStampPath(String stampPath) {
		this.stampPath = stampPath;
	}
	public String getStampNameHtml() {
		return stampNameHtml;
	}
	public void setStampNameHtml(String stampNameHtml) {
		this.stampNameHtml = stampNameHtml;
	}
	public String getInertText() {
		return inertText;
	}
	public void setInertText(String inertText) {
		this.inertText = inertText;
	}
	public String getQfStampFlag() {
		return qfStampFlag;
	}
	public void setQfStampFlag(String qfStampFlag) {
		this.qfStampFlag = qfStampFlag;
	}
	public String getStampName() {
		return stampName;
	}
	public void setStampName(String stampName) {
		this.stampName = stampName;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getStampFlag() {
		return stampFlag;
	}
	public void setStampFlag(String stampFlag) {
		this.stampFlag = stampFlag;
	}
	public String getStampID() {
		return stampID;
	}
	public void setStampID(String stampID) {
		this.stampID = stampID;
	}
	public String getImgWidth() {
		return imgWidth;
	}
	public void setImgWidth(String imgWidth) {
		this.imgWidth = imgWidth;
	}
	
	public Float getFloatImgWidth() {
		return Float.parseFloat(imgWidth);
	}
	
	public String getImgHeight() {
		return imgHeight;
	}
	public Float getFloatImgHeight() {
		return Float.parseFloat(imgHeight);
	}
	
	public void setImgHeight(String imgHeight) {
		this.imgHeight = imgHeight;
	}
	public String getStampX() {
		return stampX;
	}
	public void setStampX(String stampX) {
		this.stampX = stampX;
	}
	
	public Float getFloatStampX() {
		return Float.parseFloat(stampX);
	}
	
	public String getStampY() {
		return stampY;
	}
	public void setStampY(String stampY) {
		this.stampY = stampY;
	}
	
	public Float getFloatStampY() {
		return Float.parseFloat(stampY);
	}
	
	public String getLockFlag() {
		return lockFlag;
	}
	public void setLockFlag(String lockFlag) {
		this.lockFlag = lockFlag;
	}
	public String getMatchName() {
		return matchName;
	}
	public void setMatchName(String matchName) {
		this.matchName = matchName;
	}
	public String getStampPage() {
		return stampPage;
	}
	public void setStampPage(String stampPage) {
		this.stampPage = stampPage;
	}
	
	public Integer getIntStampPage() {
		if(StringUtil.isEmptyString(stampPage)){
			stampPage = "1";
		}
		return Integer.parseInt(stampPage);
	}
	
	public String getQianWaterMarkFlag() {
		return qianWaterMarkFlag;
	}
	public void setQianWaterMarkFlag(String qianWaterMarkFlag) {
		this.qianWaterMarkFlag = qianWaterMarkFlag;
	}
	public String getCreateTime() {
		return createTime;
	}
	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}
	
	public String getServerIp() {
		return serverIp;
	}

	public void setServerIp(String serverIp) {
		this.serverIp = serverIp;
	}

	public int getServerPort() {
		return serverPort;
	}

	public void setServerPort(int serverPort) {
		this.serverPort = serverPort;
	}

	public int getEncodeSignType() {
		return encodeSignType;
	}

	public void setEncodeSignType(int encodeSignType) {
		this.encodeSignType = encodeSignType;
	}

	public int getKeyType() {
		return keyType;
	}

	public void setKeyType(int keyType) {
		this.keyType = keyType;
	}

	public String getKeyName() {
		return keyName;
	}

	public void setKeyName(String keyName) {
		this.keyName = keyName;
	}

	public String getMultiServer() {
		return multiServer;
	}

	public void setMultiServer(String multiServer) {
		this.multiServer = multiServer;
	}

	public void setSignType(int signType) {
		this.signType = signType;
	}

	public String getCerNo() {
		return cerNo;
	}

	public void setCerNo(String cerNo) {
		this.cerNo = cerNo;
	}

    public String getPrivateKeyName() {
        return privateKeyName;
    }

    public void setPrivateKeyName(String privateKeyName) {
        this.privateKeyName = privateKeyName;
    }

    public int getPrintSeal() {
		return printSeal;
	}

	public void setPrintSeal(int printSeal) {
		this.printSeal = printSeal;
	}

	public String getSignFieldName() {
		return signFieldName;
	}

	public void setSignFieldName(String signFieldName) {
		this.signFieldName = signFieldName;
	}

	public String getSignReason() {
		return signReason;
	}

	public void setSignReason(String signReason) {
		this.signReason = signReason;
	}

	public String getSignLocation() {
		return signLocation;
	}

	public void setSignLocation(String signLocation) {
		this.signLocation = signLocation;
	}

	public int getCertificationLevel() {
		return certificationLevel;
	}

	public void setCertificationLevel(int certificationLevel) {
		this.certificationLevel = certificationLevel;
	}

	public int getNeedCompleteCer() {
		return needCompleteCer;
	}

	public void setNeedCompleteCer(int needCompleteCer) {
		this.needCompleteCer = needCompleteCer;
	}

	public int getFatherType() {
		return fatherType;
	}

	public void setFatherType(int fatherType) {
		this.fatherType = fatherType;
	}

	public int getKeyNeedRect() {
		return keyNeedRect;
	}

	public void setKeyNeedRect(int keyNeedRect) {
		this.keyNeedRect = keyNeedRect;
	}

	public int getMultiKeyWord() {
		return multiKeyWord;
	}

	public void setMultiKeyWord(int multiKeyWord) {
		this.multiKeyWord = multiKeyWord;
	}

	public int getMoveType() {
		return moveType;
	}

	public void setMoveType(int moveType) {
		this.moveType = moveType;
	}

	public int getPositive() {
		return positive;
	}

	public void setPositive(int positive) {
		this.positive = positive;
	}

	public int getRectPageNo() {
		return rectPageNo;
	}

	public void setRectPageNo(int rectPageNo) {
		this.rectPageNo = rectPageNo;
	}

	public float getRectLeft() {
		return rectLeft;
	}

	public void setRectLeft(float rectLeft) {
		this.rectLeft = rectLeft;
	}

	public float getRectRight() {
		return rectRight;
	}

	public void setRectRight(float rectRight) {
		this.rectRight = rectRight;
	}

	public float getRectTop() {
		return rectTop;
	}

	public void setRectTop(float rectTop) {
		this.rectTop = rectTop;
	}

	public float getRectBottom() {
		return rectBottom;
	}

	public void setRectBottom(float rectBottom) {
		this.rectBottom = rectBottom;
	}

	public int getQfMultiSign() {
		return qfMultiSign;
	}

	public void setQfMultiSign(int qfMultiSign) {
		this.qfMultiSign = qfMultiSign;
	}

	public int getQfPosCoord() {
		return qfPosCoord;
	}

	public void setQfPosCoord(int qfPosCoord) {
		this.qfPosCoord = qfPosCoord;
	}

	public int getQfStartWidth() {
		return qfStartWidth;
	}

	public void setQfStartWidth(int qfStartWidth) {
		this.qfStartWidth = qfStartWidth;
	}
	public String getCredentialsFlag() {
		return credentialsFlag;
	}
	public void setCredentialsFlag(String credentialsFlag) {
		this.credentialsFlag = credentialsFlag;
	}
	public String getCredentialsHtml() {
		return credentialsHtml;
	}
	public void setCredentialsHtml(String credentialsHtml) {
		this.credentialsHtml = credentialsHtml;
	}
	public String getCredentialsId() {
		return credentialsId;
	}
	public void setCredentialsId(String credentialsId) {
		this.credentialsId = credentialsId;
	}
	public String getQfRuleId() {
		return qfRuleId;
	}
	public void setQfRuleId(String qfRuleId) {
		this.qfRuleId = qfRuleId;
	}
	public String getQfRuleHtml() {
		return qfRuleHtml;
	}
	public void setQfRuleHtml(String qfRuleHtml) {
		this.qfRuleHtml = qfRuleHtml;
	}

	public String getServerUrlSuffix() {
		return serverUrlSuffix;
	}
	public void setServerUrlSuffix(String serverUrlSuffix) {
		this.serverUrlSuffix = serverUrlSuffix;
	}
	
	
	public boolean isPdfHasSM2Signed() {
		return pdfHasSM2Signed;
	}
	public void setPdfHasSM2Signed(boolean pdfHasSM2Signed) {
		this.pdfHasSM2Signed = pdfHasSM2Signed;
	}
	
	public boolean isPdfHasRSASigned() {
		return pdfHasRSASigned;
	}
	public void setPdfHasRSASigned(boolean pdfHasRSASigned) {
		this.pdfHasRSASigned = pdfHasRSASigned;
	}
	
	public String getOtherStampId() {
		return otherStampId;
	}
	public void setOtherStampId(String otherStampId) {
		this.otherStampId = otherStampId;
	}
	public String getSignStampId() {
		return signStampId;
	}
	public void setSignStampId(String signStampId) {
		this.signStampId = signStampId;
	}
	public String getWaterStampId() {
		return waterStampId;
	}
	public void setWaterStampId(String waterStampId) {
		this.waterStampId = waterStampId;
	}
	public String getMergeId() {
		return mergeId;
	}
	public void setMergeId(String mergeId) {
		this.mergeId = mergeId;
	}

	public String getEncropytToPdf() {
		return encropytToPdf;
	}

	public void setEncropytToPdf(String encropytToPdf) {
		this.encropytToPdf = encropytToPdf;
	}

	public int getSignType() {
		return signType;
	}
	public static GStamp packToGStamp(ISign iSign) {
		GStamp stamp = new GStamp();
		stamp.setStampFlag("true".equals(iSign.getStampFlag())?true:false);
		stamp.setFilePath(iSign.getStampPath());
		stamp.setImgWidth(iSign.getImgWidth());
		stamp.setImgHeight(iSign.getImgHeight());
		stamp.setStamp_x(iSign.getStampX());
		stamp.setStamp_y(iSign.getStampY());
		stamp.setMatchName(iSign.getMatchName());
		stamp.setStampPage(iSign.getStampPage());
		stamp.setCorStampName(iSign.getStampName());
		stamp.setQfRuleId(iSign.getQfRuleId());
		stamp.setSealType(iSign.getSignType()+"");
		return stamp;
	}
	

	public void parseFrontOtherSign(ISign iSignFront, ISign iSign) {
		iSign.setStampFlag(iSignFront.getStampFlag());
		iSign.setStampID(iSignFront.getStampID());
		iSign.setQianWaterMarkFlag(iSignFront.getQianWaterMarkFlag());
		iSign.setQfStampFlag(iSignFront.getQfStampFlag());
		
		iSign.setServerIp(iSignFront.getServerIp());
		iSign.setServerPort(iSignFront.getServerPort());
		iSign.setKeyType(iSignFront.getKeyType());
		iSign.setEncodeSignType(iSignFront.getEncodeSignType());
		iSign.setSignType(iSignFront.getSignType());
		iSign.setCerNo(iSignFront.getCerNo());
		iSign.setPrintSeal(iSignFront.getPrintSeal());
	
		iSign.setCertificationLevel(iSignFront.getCertificationLevel());
		iSign.setKeyNeedRect(iSignFront.getKeyNeedRect());
		iSign.setMultiKeyWord(iSignFront.getMultiKeyWord());
		iSign.setMoveType(iSignFront.getMoveType());
		iSign.setPositive(iSignFront.getPositive());
		iSign.setSignFieldName(iSignFront.getSignFieldName());
		
		iSign.setRectPageNo(iSignFront.getRectPageNo());
		iSign.setRectLeft(iSignFront.getRectLeft());
		iSign.setRectRight(iSignFront.getRectRight());
		iSign.setRectTop(iSignFront.getRectTop());
		iSign.setRectBottom(iSignFront.getRectBottom());
		
	}
	
	public static void copyISignToISign(ISign newSign , ISign oldSign) throws Exception{
		newSign.setCerNo(oldSign.getCerNo());
		newSign.setKeyName(oldSign.getKeyName());
		newSign.setCertificationLevel(oldSign.getCertificationLevel());
		newSign.setCredentialsFlag(oldSign.getCredentialsFlag());
		newSign.setCredentialsHtml(oldSign.getCredentialsHtml());
		newSign.setCredentialsId(oldSign.getCredentialsId());
		newSign.setEncodeSignType(oldSign.getEncodeSignType());
		newSign.setFatherType(oldSign.getFatherType());
		newSign.setId(oldSign.getId());
		newSign.setImgHeight(oldSign.getImgHeight());
		newSign.setImgWidth(oldSign.getImgWidth());
		newSign.setInertText(oldSign.getInertText());
		newSign.setKeyNeedRect(oldSign.getKeyNeedRect());
//		newSign.setKeyType(oldSign.getKeyType());
		if(oldSign.getKeyType() == KeyLoaderType.TYPE_CEBA_KEY){
			//如果是key签名则保持原来不变
			newSign.setKeyType(oldSign.getKeyType());
		}else{
			//如果是服务器签名则从配置文件中拿值
			newSign.setKeyType(SystemHelper.getServerType());
		}
		newSign.setLockFlag(oldSign.getLockFlag());
		newSign.setMatchName(oldSign.getMatchName());
		newSign.setMoveType(oldSign.getMoveType());
		newSign.setMultiKeyWord(oldSign.getMultiKeyWord());
		newSign.setMultiServer(oldSign.getMultiServer());
		newSign.setNeedCompleteCer(oldSign.getNeedCompleteCer());
		newSign.setPositive(oldSign.getPositive());
		newSign.setPrintSeal(oldSign.getPrintSeal());
		newSign.setQfMultiSign(oldSign.getQfMultiSign());
		newSign.setQfPosCoord(oldSign.getQfPosCoord());
		newSign.setQfRuleHtml(oldSign.getQfRuleHtml());
		newSign.setQfRuleId(oldSign.getQfRuleId());
		newSign.setQfStampFlag(oldSign.getQfStampFlag());
		newSign.setQfStartWidth(oldSign.getQfStartWidth());
		newSign.setQianWaterMarkFlag(oldSign.getQianWaterMarkFlag());
		newSign.setRectBottom(oldSign.getRectBottom());
		newSign.setRectLeft(oldSign.getRectLeft());
		newSign.setRectPageNo(oldSign.getRectPageNo());
		newSign.setRectRight(oldSign.getRectRight());
		newSign.setRectTop(oldSign.getRectTop());
		newSign.setServerIp(oldSign.getServerIp());
		if(oldSign.getServerPort() != 0){
			newSign.setServerPort(oldSign.getServerPort());
		}
		newSign.setServerUrlSuffix(oldSign.getServerUrlSuffix());
		newSign.setSignFieldName(oldSign.getSignFieldName());
		newSign.setSignLocation(oldSign.getSignLocation());
		newSign.setSignReason(oldSign.getSignReason());
		newSign.setSignType(oldSign.getSignType());
		newSign.setStampFlag(oldSign.getStampFlag());
		newSign.setStampID(oldSign.getStampID());
		newSign.setStampName(oldSign.getStampName());
		newSign.setStampNameHtml(oldSign.getStampNameHtml());
		newSign.setStampPage(oldSign.getStampPage());
		newSign.setStampPath(oldSign.getStampPath());
		newSign.setStampX(oldSign.getStampX());
		newSign.setStampY(oldSign.getStampY());
		newSign.setCreateTime(oldSign.getCreateTime());
		newSign.setAllowPdfContentCopy(oldSign.getAllowPdfContentCopy());
		newSign.setAllowPdfPrint(oldSign.getAllowPdfPrint());
	}
}
